home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 500 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c,gnu.gcc.help
  4. Subject: Re: Casting unsigned short as unsigned int -> Bus error
  5. Date: Fri, 05 Jan 96 21:59:46 GMT
  6. Organization: none
  7. Message-ID: <820879186snz@genesis.demon.co.uk>
  8. References: <simmons.820857453@rzdspc1>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <simmons.820857453@rzdspc1>
  15.            simmons@rzdspc1.informatik.uni-hamburg.de "Geoffrey Simmons" writes:
  16.  
  17. >I have a pointer to a struct with a member declared as unsigned short:
  18. >
  19. >        typedef struct {
  20. >                ...
  21. >                unsigned short myshort;
  22. >                ...
  23. >                } RecType;
  24. >
  25. >        RecType *MyRec;
  26. >
  27. >Now when I try to dereference that member, casting it to (unsigned int),
  28. >I get a bus error:
  29. >
  30. >        unsigned int myint;
  31. >
  32. >        myint = (unsigned int) MyRec->myshort;  /* Bus error! */
  33. >
  34. >I'm using GCC 2.7.2 on a SparcStation running SunOS 4.1.4. I've made sure
  35. >that the pointer points to valid data.
  36.  
  37. If that is so then the code is perfectly valid (and the cast is redundant) -
  38. your problem is caused somewhere else. Post a minimal compilable program that
  39. demonstrates the problem.
  40.  
  41. -- 
  42. -----------------------------------------
  43. Lawrence Kirby | fred@genesis.demon.co.uk
  44. Wilts, England | 70734.126@compuserve.com
  45. -----------------------------------------
  46.